package contact.controller;


import java.util.ArrayList;
import java.util.List;

import model.db.Vertical;

import org.hibernate.HibernateException;
import org.hibernate.Session;

import contact.util.HibernateUtil;

public class VerticalManager {


	
	public Vertical getVertical(long ids) {
		
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Vertical v=null;
		
		ArrayList<Vertical>vl=null;
		try {
			
			vl = (ArrayList<Vertical>) session.createQuery("from Vertical where id=" + ids).list();
			
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		
		if(vl!=null && vl.size()>0){
			
			v=vl.get(0);
		}
		return v;
	//	return v;
	}
	
	
	
	public List<Vertical> list() {
		
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<Vertical> queries = null;
		try {
			
			queries = (List<Vertical>)session.createQuery("from Vertical").list();
			
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		return queries;
	}
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
